package fightingTechnologyGame;

import java.util.Random;

public class Role {
    private String name;
    private int blood;

    public Role() {
    }

    public Role(String name, int blood) {
        this.name = name;
        this.blood = blood;
    }

    /**
     * 获取
     * @return name
     */
    public String getName() {
        return name;
    }

    /**
     * 设置
     * @param name
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * 获取
     * @return blood
     */
    public double getBlood() {
        return blood;
    }

    /**
     * 设置
     * @param blood
     */
    public void setBlood(int blood) {
        this.blood = blood;
    }

    public String toString() {
        return "Role{name = " + name + ", blood = " + blood + "}";
    }

    // 定义一个方法用来攻击别人
    public void attack(Role role){
        //计算造成了的伤害1~20点
        Random r = new Random();
        int hurt = r.nextInt(20+1);

        //攻击role后，role剩余血量
        int residueBlood = this.blood - hurt;
        //收攻击者血量可能为负数，所以需要判断
        residueBlood = residueBlood < 0 ? 0 : residueBlood;
        // 修改一下受攻击的人的血量
        role.setBlood(residueBlood);

        System.out.println(this.name+"拎起拳头攻击了"+role.getName()+",造成了"+hurt+"点血量，恐龙还剩下"+role.getBlood()+"点血量");
    }
}
